package com.dongwq

class PageDemoController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

//	static beforeInterceptor = [action:this.&bfInter]
//	
//	def bfInter = {
//		
//		println "actionName"
//		return true;
//	}
	
	def blueprintDemo=
	{
		
	}
    def blueprintSampleDemo=
    {
    	
    }
	
	def scaffold = true
	
	def utilForword =
	{
		def util = params.util;
		if( util)
		{
			render(view:util);
		}else
		{
			render(text:"this util do not exist")
		}
	}
	
	def dispatcher =
	{
		def pageDemo = PageDemo.get(params.id)
		if( pageDemo )
		{
			println pageDemo.uri
			render(view:pageDemo.uri);
		}else
		{
			render(text:"this pageDemoInstance do not exist")
		}
	}
	
    def index = {
        redirect(action: "list", params: params)
    }

    def list = {
        params.max = Math.min(params.max ? params.int('max') : 10, 100)
        [pageDemoInstanceList: PageDemo.list(params), pageDemoInstanceTotal: PageDemo.count()]
    }

    def create = {
        def pageDemoInstance = new PageDemo()
        pageDemoInstance.properties = params
        return [pageDemoInstance: pageDemoInstance]
    }

    def save = {
        def pageDemoInstance = new PageDemo(params)
        if (pageDemoInstance.save(flush: true)) {
            flash.message = "${message(code: 'default.created.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), pageDemoInstance.id])}"
            redirect(action: "show", id: pageDemoInstance.id)
        }
        else {
            render(view: "create", model: [pageDemoInstance: pageDemoInstance])
        }
    }

    def show = {
        def pageDemoInstance = PageDemo.get(params.id)
        if (!pageDemoInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), params.id])}"
            redirect(action: "list")
        }
        else {
            [pageDemoInstance: pageDemoInstance]
        }
    }

    def edit = {
        def pageDemoInstance = PageDemo.get(params.id)
        if (!pageDemoInstance) {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), params.id])}"
            redirect(action: "list")
        }
        else {
            return [pageDemoInstance: pageDemoInstance]
        }
    }

    def update = {
        def pageDemoInstance = PageDemo.get(params.id)
        if (pageDemoInstance) {
            if (params.version) {
                def version = params.version.toLong()
                if (pageDemoInstance.version > version) {
                    
                    pageDemoInstance.errors.rejectValue("version", "default.optimistic.locking.failure", [message(code: 'pageDemo.label', default: 'PageDemo')] as Object[], "Another user has updated this PageDemo while you were editing")
                    render(view: "edit", model: [pageDemoInstance: pageDemoInstance])
                    return
                }
            }
            pageDemoInstance.properties = params
            if (!pageDemoInstance.hasErrors() && pageDemoInstance.save(flush: true)) {
                flash.message = "${message(code: 'default.updated.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), pageDemoInstance.id])}"
                redirect(action: "show", id: pageDemoInstance.id)
            }
            else {
                render(view: "edit", model: [pageDemoInstance: pageDemoInstance])
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), params.id])}"
            redirect(action: "list")
        }
    }

    def delete = {
        def pageDemoInstance = PageDemo.get(params.id)
        if (pageDemoInstance) {
            try {
                pageDemoInstance.delete(flush: true)
                flash.message = "${message(code: 'default.deleted.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), params.id])}"
                redirect(action: "list")
            }
            catch (org.springframework.dao.DataIntegrityViolationException e) {
                flash.message = "${message(code: 'default.not.deleted.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), params.id])}"
                redirect(action: "show", id: params.id)
            }
        }
        else {
            flash.message = "${message(code: 'default.not.found.message', args: [message(code: 'pageDemo.label', default: 'PageDemo'), params.id])}"
            redirect(action: "list")
        }
    }
}
